﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace QLHXNK.DataAccess
{
    class ExpensesData
    {
        #region --------------------------------------------Thêm, Xoá, Sửa-----------------------------------------
        //Thêm:
        public static int Insert(String expenses_code, String expenses_name, String remark)
        {
            String strSQL = String.Format("INSERT INTO Expenses (expenses_code, expenses_name, remark) VALUES ('{0}', '{1}', '{2}')", expenses_code.Replace("'", "''"), expenses_name.Replace("'", "''"), remark.Replace("'", "''"));
            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }
       
        //Xóa:
        public static int Delete(int ID)
        {
            String strSQL = String.Format("DELETE FROM Expenses WHERE ID = {0}", ID);
            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }

        //Sửa:
        public static int Update(int ID, String expenses_code, String expenses_name, String remark)
        {
            String strSQL = String.Format("UPDATE  Expenses SET expenses_code = '{0}', expenses_name = '{1}',  remark = '{2}' WHERE ID = {3}", expenses_code.Replace("'", "''"), expenses_name.Replace("'", "''"),remark.Replace("'", "''"), ID);
            
            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }
        #endregion

        #region -----------------------------------------Lấy danh sách----------------------------------
        public static DataTable getExpensesList(String strSQL)
        {
            if (strSQL == "")
                strSQL = "SELECT * FROM Expenses";
            return MyDataTransfer.executeQueryCommand(strSQL);
        }
        #endregion
    }
}
